package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.event.ToastEvent;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.view.refundgoods.RefundGoodsView;
import com.superman.supermarket.client.view.refundgoods.RefundGoodsView.RefundGoodsViewPresenter;;

/**
 * 退货
 * 
 * @author superman
 * @version 2018年8月15日下午5:07:35
 */
public class RefundGoodsActivity extends ShopAbstractActivity implements RefundGoodsViewPresenter {

	@Inject
	RefundGoodsView refundGoodsView;
	private String refundId;

	private void getExpressCompanyList() {
		postman.post("refund/express/company", null, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				refundGoodsView.setExpressCompanyList(XJsonUtil.getList(response));
			}
		});
	}

	@Override
	public IPageView getView() {
		return refundGoodsView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		return this;
	}

	@Override
	public void onActivity(EventBus eventBus) {
		// TODO Auto-generated method stub

	}

	@Override
	public void popToRefresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void popToRefresh(Object contextData) {
		// TODO Auto-generated method stub

	}

	@Override
	public void pushToRefresh() {
		refundId = Window.Location.getParameter("refundid");
		getExpressCompanyList();
	}

	@Override
	public void submit(Map<String, Object> map) {
		Map<String, Object> postMap = new HashMap<String, Object>();
		postMap.put("REFUND_ID", refundId);
		postMap.putAll(map);
		postman.post("refund/return", postMap, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("REFUND_ID", refundId);
				eventBus.fireEvent(new ToastEvent("已提交"));
				placeController.back(map);
			}
		});
	}

}
